#include <iostream>
#include "blockqueue.hpp"
using namespace std;
int num=0;
pthread_mutex_t mutex;
pthread_cond_t consumer_cond;
pthread_cond_t productor_cond;


void * consumer(void * args)
{
   BlockQueue<int> *bq=static_cast<BlockQueue <int> *>(args);
    while(true) //消费者不断消费
    {
        int data=0;
        bq->pop(&data);
        cout<<"consumer:"<<data<<endl;
    }
}

void * productor(void * args)
{
    BlockQueue<int> *bq=static_cast<BlockQueue <int> *>(args);
    while(true)
    {
    bq->push(num);
    cout<<"productor"<<num<<endl;
    num++;
    }
}

int main()
{
    queue<int> q;
    BlockQueue<int>* bq=new BlockQueue<int>(10);
    //单生产单消费
    pthread_t c,p;
    pthread_create(&c,nullptr,consumer,bq);
    pthread_create(&p,nullptr,productor,bq);


    pthread_join(c,nullptr);
    pthread_join(p,nullptr);

    delete bq;

    return 0;
}